package com.atguigu.gmall.product.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "商品基础属性接口")
@RequestMapping("/admin/product")
@RestController
public class ManageController {

    @Autowired
    private ManageService manageService;

    @GetMapping("/getCategory1")
    public Result getCategory1(){
        List<BaseCategory1> baseCategory1List = manageService.getCategory1();
        return Result.ok(baseCategory1List);
    }


    @GetMapping("/getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable long category1Id){
        List<BaseCategory2> baseCategory2List = manageService.getCategory2(category1Id);
        return Result.ok(baseCategory2List);
    }

    @GetMapping("/getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable long category2Id){
        List<BaseCategory3> baseCategory3List = manageService.getCategory3(category2Id);
        return Result.ok(baseCategory3List);
    }

    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result getAttrInfoList(
            @PathVariable long category1Id,
            @PathVariable long category2Id,
            @PathVariable long category3Id){
        List<BaseAttrInfo> attrInfoList = manageService.getAttrInfoList(category1Id,category2Id,category3Id);
        return Result.ok(attrInfoList);

    }



    @PostMapping("/saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        manageService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }


    @GetMapping("/getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable Long attrId){
        BaseAttrInfo baseAttrInfo = manageService.getAttrInfo(attrId);
        List<BaseAttrValue> baseAttrValueList  = baseAttrInfo.getAttrValueList();
        return Result.ok(baseAttrValueList );
    }


    @GetMapping("baseTrademark/{page}/{limit}")
    public Result baseTrademark(
            @PathVariable Integer page,
            @PathVariable Integer limit){

        IPage iPage = manageService.baseTrademark(page,limit);
        return Result.ok(iPage);

    }

    //获取商品集合分页查询
    @GetMapping("/{page}/{limit}")
    public Result findSpuList(
            @PathVariable Integer page,
            @PathVariable Integer limit,
            Long category3Id){
        IPage iPage = manageService.findSpuList(page,limit,category3Id);
        return Result.ok(iPage);
    }


    //查询所遇品牌列表
    @GetMapping("/baseTrademark/getTrademarkList")
    public Result getTrademarkList(){
        List<BaseTrademark> baseTrademarks = manageService.getTrademarkList();
        return Result.ok(baseTrademarks);
    }



    //查询销售属性列表
    @GetMapping("/baseSaleAttrList")
    public Result baseSaleAttrList(){

        List<BaseSaleAttr> baseSaleAttrList = manageService.baseSaleAttrList();
        return Result.ok(baseSaleAttrList);
    }



    //保存spu
    @PostMapping("/saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfo spuInfo){
        manageService.saveSpuInfo(spuInfo);
        return Result.ok();

    }


    //查询SPU所有图片,显示在SKU添加页面上 ,以便勾选
    @GetMapping("/spuImageList/{spuId}")
    public Result spuImageList(@PathVariable Long spuId){
        List<SpuImage> spuImageList =  manageService.spuImageList(spuId);
        return Result.ok(spuImageList);
    }


    //根据SPUID查询所有销售属性及属性值表
    @GetMapping("/spuSaleAttrList/{spuId}")
    public Result spuSaleAttrList(@PathVariable Long spuId){
        List<SpuSaleAttr> spuSaleAttrList = manageService.spuSaleAttrList(spuId);
        return Result.ok(spuSaleAttrList);
    }

    //保存SKU
    @PostMapping("/saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){
        manageService.saveSkuInfo(skuInfo);

        return Result.ok();
    }


    //查询SKU分页
    @GetMapping("/list/{page}/{limit}")
    public Result skuList(  @PathVariable Integer page,
                            @PathVariable Integer limit){
        IPage iPage = manageService.skuList(page,limit);
        return Result.ok(iPage);
    }
    //上架
    @GetMapping("/onSale/{skuId}")
    public Result onSale(@PathVariable Long skuId){
        manageService.onSale(skuId);
        return Result.ok();
    }

    //下架
    @GetMapping("/cancelSale/{skuId}")
    public Result cancelSale(@PathVariable Long skuId){
        manageService.cancelSale(skuId);
        return Result.ok();
    }







}
